/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * createProductPanel.java
 *
 * Created on 09-06-2010, 09:41:40
 */

package gruppe1projekt.GUILayer.product;

import gruppe1projekt.ControllerLayer.ProductController;
import gruppe1projekt.GUILayer.BaseWindow;
import javax.swing.JOptionPane;

/**
 *
 * @author Kristian Byrialsen
 */
public class createProductPanel extends BaseWindow {

    /** Creates new form createProductPanel */
    public createProductPanel() 
    {
        RequiresLogin = true;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel62 = new javax.swing.JLabel();
        addproduct = new javax.swing.JButton();
        jLabel63 = new javax.swing.JLabel();
        jLabel64 = new javax.swing.JLabel();
        jLabel65 = new javax.swing.JLabel();
        txtbeskrivelse = new javax.swing.JTextField();
        txttype = new javax.swing.JTextField();
        txtkoebspris = new javax.swing.JTextField();
        txtbarcode = new javax.swing.JTextField();
        bslet = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        txtantal = new javax.swing.JTextField();

        setMaximumSize(null);

        jPanel1.setMaximumSize(null);

        jLabel62.setText("Type");

        addproduct.setText("Opret produkt");
        addproduct.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addproductActionPerformed(evt);
            }
        });

        jLabel63.setText("Beskrivelse");

        jLabel64.setText("Købspris");

        jLabel65.setText("Stregkode");

        txtbeskrivelse.setFont(new java.awt.Font("Verdana", 0, 12));
        txtbeskrivelse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtbeskrivelseActionPerformed(evt);
            }
        });

        txttype.setFont(new java.awt.Font("Verdana", 0, 12));
        txttype.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txttypeActionPerformed(evt);
            }
        });

        txtkoebspris.setFont(new java.awt.Font("Verdana", 0, 12));
        txtkoebspris.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtkoebsprisActionPerformed(evt);
            }
        });

        txtbarcode.setFont(new java.awt.Font("Verdana", 0, 12));
        txtbarcode.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtbarcodeActionPerformed(evt);
            }
        });

        bslet.setText("Slet informationer");
        bslet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bsletActionPerformed(evt);
            }
        });

        jLabel1.setText("Antal varer på lager");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel63)
                            .addComponent(jLabel62)
                            .addComponent(jLabel64)
                            .addComponent(jLabel65))
                        .addGap(52, 52, 52))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txttype)
                    .addComponent(txtbeskrivelse)
                    .addComponent(txtkoebspris)
                    .addComponent(txtbarcode)
                    .addComponent(txtantal, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(addproduct)
                        .addGap(18, 18, 18)
                        .addComponent(bslet)))
                .addContainerGap(50, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(36, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txttype, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel62))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel63)
                    .addComponent(txtbeskrivelse, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtkoebspris, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel64))
                .addGap(27, 27, 27)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtbarcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel65))
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtantal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(33, 33, 33)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addproduct)
                    .addComponent(bslet))
                .addGap(35, 35, 35))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtkoebsprisActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_txtkoebsprisActionPerformed
    {//GEN-HEADEREND:event_txtkoebsprisActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtkoebsprisActionPerformed

    private void txtbarcodeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_txtbarcodeActionPerformed
    {//GEN-HEADEREND:event_txtbarcodeActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtbarcodeActionPerformed

    private void bsletActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_bsletActionPerformed
    {//GEN-HEADEREND:event_bsletActionPerformed

        cleartext();
    
}//GEN-LAST:event_bsletActionPerformed

    private void txttypeActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_txttypeActionPerformed
    {//GEN-HEADEREND:event_txttypeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txttypeActionPerformed

    private void txtbeskrivelseActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_txtbeskrivelseActionPerformed
    {//GEN-HEADEREND:event_txtbeskrivelseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtbeskrivelseActionPerformed

    private void addproductActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_addproductActionPerformed
    {//GEN-HEADEREND:event_addproductActionPerformed
        ProductController productcontroller = new ProductController();

        String type = txttype.getText();
        String beskrivelse = txtbeskrivelse.getText();
        int koebspris = Integer.parseInt(txtkoebspris.getText());
        long barcode = Long.parseLong( txtbarcode.getText());
        int antal = Integer.parseInt(txtantal.getText());


        productcontroller.createProduct(type, beskrivelse, koebspris, barcode, antal);

        cleartext();
    }//GEN-LAST:event_addproductActionPerformed

   private void cleartext()
   {
        txttype.setText("");
        txtbeskrivelse.setText("");
        txtkoebspris.setText("");
        txtbarcode.setText("");
        txtantal.setText("");
   }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addproduct;
    private javax.swing.JButton bslet;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel62;
    private javax.swing.JLabel jLabel63;
    private javax.swing.JLabel jLabel64;
    private javax.swing.JLabel jLabel65;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtantal;
    private javax.swing.JTextField txtbarcode;
    private javax.swing.JTextField txtbeskrivelse;
    private javax.swing.JTextField txtkoebspris;
    private javax.swing.JTextField txttype;
    // End of variables declaration//GEN-END:variables

}